package com.example.logistics_oa.controller.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @Description:
 * @Author:李博文
 * @Date:2022/10/13 20:06
 *
 *  审核工资单要用到的日期
 *
 */
public class GetDate {

    //获取这个月的第一天
    public String getThisDay(){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        //获得本月第一天
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        String firstDay = sdf.format(calendar.getTime());
        return  firstDay;

    }


    //获取上次发薪资 日期  的下个月一号
    public String getNextDay(Date zhidingDasdte){

        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");


        Calendar calendar = Calendar.getInstance();
        calendar.setTime(zhidingDasdte);
        calendar.set(Calendar.DAY_OF_MONTH,+1);
        calendar.add(Calendar.MONTH, +1);
        String format1 = format.format(calendar.getTime());
        return format1;

    }


    //获取上个月的第一天
    public String getLastDay(){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        //获得本月第一天
        calendar.add(Calendar.MONTH, -1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        String firstDay = sdf.format(calendar.getTime());
        return  firstDay;

    }



}
